#ifndef FRIDGECONTROLLER_H
#define FRIDGECONTROLLER_H

#include <QNetworkAccessManager>
#include <QWidget>
#include <iostream>
#include "json/json.h"
#include <fstream>
#include <QObject>
#include <QString>
#include <QtNetwork>
#include <QJsonObject>
#include <QJsonDocument>

struct fmessageInfo{
    int code;
    QString data;
    QString message;
};
struct friageInfo
{
    int version;
    QString gmtCreate;
    QString gmtModified;
    int valid;
    int isDeleted;
    int id;
    QString password;
    QString salt;
    QString name;
    QString createTime;
    QString activeTime;
    int guarantee;
    int userId;
    QString activeCode;
};
struct synFoodInfo
{
    int version;
    QString gmtCreate;
    QString gmtModified;
    int createUser;
    int createId;
    QString name;
    int type;
    int shelfLife;
    int unit;
    QString info;
    QString alias;
    QString pic;
};
struct synFridgeInfo
{
    int version;
    QString gmtCreate;
    QString gmtModified;
    int foodId;
    int amount;
    int fridgeId;
    int userId;
};
struct synRemindInfo
{
    int version;
    QString gmtCreate;
    QString gmtModified;
    int foodId;
    int amount;
    int fridgeId;
    int userId;
    QString date;
    int id;
};


class FridgeController : public QObject
{
    Q_OBJECT
public:
    explicit FridgeController(QObject *parent = nullptr);
    QNetworkAccessManager *accessManager;
    QNetworkRequest request;
    QByteArray postData;
    QNetworkReply* reply;
    fmessageInfo m_message;
    QList<friageInfo> fridgeList;
    void FridgesynchronizeForm(QString token,
                               QList<synFoodInfo> foodList,
                               QList<synFridgeInfo> fridgeStorageList,
                               QList<synRemindInfo> remindList,
                               int fridgeId);
    void FridgeBind(QString token,QString activeCode,QString id,QString password);
    void FridgeList(QString token);
    void FridgeChangePass(QString token,int id,QString confirm,QString newPass,QString oldPass);
    void FridgeUnbind(QString token,int version,
                                    QString gmtCreate,
                                    QString gmtModified,
                                    int valid,
                                    int isDeleted,
                                    int id,
                                    QString password,
                                    QString salt,
                                    QString name,
                                    QString createTime,
                                    QString activeTime,
                                    int guarantee,
                                    int userId,
                                    QString activeCode);
    void FridgeUpdate(QString token,int version,
                      QString gmtCreate,
                      QString gmtModified,
                      int valid,
                      int isDeleted,
                      int id,
                      QString password,
                      QString salt,
                      QString name,
                      QString createTime,
                      QString activeTime,
                      int guarantee,
                      int userId,
                      QString activeCode);
private slots:
    void finishedSlot(QNetworkReply *reply);
signals:
    void bindSuccess();
    void listSuccess();
    void changePassSuccess();
    void unBindSuccess();
    void updateSuccess();
};

#endif // FRIDGECONTROLLER_H
